package file.listener;

import file.FileFrame;
import file.handle.FilePannel;
import file.listener.observer.TreeManager;
import file.listener.observer.impl.FilePannelImpl;
import file.listener.observer.impl.JLabelPathImpl;
import file.model.FileModel;

import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * @Author: zou
 * @email: 704572528@qq.com
 * @Date: 2020/10/28 16:10
 */
public class LeftTreeListener extends FileFrameAbstract implements TreeSelectionListener , MouseListener {


    public LeftTreeListener ( FileFrame fileFrame) {
        super(fileFrame);
    }

    @Override
    public void valueChanged(TreeSelectionEvent e) {

    }

    /**
     * 鼠标点击
     * @param e
     */
    @Override
    public void mouseClicked(MouseEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) super.fileFrame.getLeftTree().getLastSelectedPathComponent();
        if (node == null){
            return;
        }//if
        Object object = node.getUserObject();
        FileModel files = new FileModel(object.toString());
        if (object instanceof FileModel) {
            files = (FileModel) object;
            TreeManager manager = new TreeManager();
            manager.addTreeObserver(new FilePannelImpl(fileFrame));
            manager.addTreeObserver(new JLabelPathImpl(fileFrame));
            manager.notifyTreeObserver(files);
            file.handle.impl.FilePannelImpl.isChange = false;
        }
        System.out.println(files.toString());
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
